OneM2M_Functions.ttcn 130 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
 *  @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 26
	group ConfigFunctions {
		
27 28 29
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
30
		function f_cf01Up(in boolean p_auxiliaryAe2Required := false) runs on AeSimu {
31
			
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 90
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
91 92 93
			activate(a_cse_cf02_ae1());
			vc_cse1.start(f_cf02UpCse1());
			vc_cse1.done;
94
				
95
			// Connect
96
			
97
			//Initialze the IUT
98
							
99
		} // end f_cf02Up
100 101 102 103 104 105 106
		
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the CSE1
		*/
		function f_cf02UpCse1() runs on CseSimu {
			
			// Variables
107
			var PrimitiveContent v_cSEBaseResource;
108 109
			vc_config := e_cf02;
			vc_testSystemRole := e_cse;		
110 111 112 113 114 115 116 117 118
			
			// Map
			map(self:mccPort, system:mccPort);
			map(self:mccPortIn, system:mccPortIn);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf02_cse1());
			
119 120 121
			v_cSEBaseResource := f_cse_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
122 123 124
			//Initialze the IUT
							
		} // end f_cf02UpCse1
125

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

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

			// Connect
			
231
			//Initialize the IUT
232 233 234 235 236
			
		} // end f_cf03Up

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

	}//end group configFunctions
	
	group InfoPortCommunication {
	
		/**
		 * @desc Connection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
310 311 312 313 314
		function f_connectInfoPort(in Tester p_tester) runs on Tester {
			// Connect
			connect(self:infoPort, p_tester:infoPort);		
		} 
	
315 316 317 318
		/**
		 * @desc Disconnection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
319 320 321 322
		function f_disconnectInfoPort(in Tester p_tester) runs on Tester {
			// Disconnect
			disconnect(self:infoPort, p_tester:infoPort);		
		} 
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	
		/**
		 * @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;
				
		}
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 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
		/**
		 * @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	
494
	
495
	group CseFunctions {
496
	
497
		group PreambleFunctions {
498 499 500 501 502 503 504

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

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

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

						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_);
							}	
						}	
			
					}
				}
			
807
			}			
808 809 810 811 812
			
		}//end group postambleFunctions
		
		group AeSimuFunctions {
			
813 814 815
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
816
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
817 818 819 820
			 * @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 
			 */
821
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
822
			
823 824
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
825
				
826
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
827
			
828 829 830
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
831
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
832
						tc_ac.stop;
833
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
834 835 836 837 838
						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;
						}
839 840 841
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
842
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
843 844 845
					}
					[] mcaPort.receive {
						tc_ac.stop;
846
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
847 848
					}
					[] tc_ac.timeout {
849
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
850 851
					}
				}	
852
				
853
				f_checkAeSimuStatus();
854
				
855
				return v_resourceIndex;
856
		
857
			}
858 859 860 861 862 863 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
			
			/**
			 * @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
889
		
890 891 892 893 894 895 896
			/**
			 * @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 
			 */
897
			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;
898
				var integer v_acpAuxIndex := -1;
899
				
900
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
901
				
902 903
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
904 905 906
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
907
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
908
						tc_ac.stop;
909
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
910 911
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
912 913 914 915
						vc_acpAuxIndex := v_acpAuxIndex;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
916
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
917 918 919
					}
					[] mcaPort.receive {
						tc_ac.stop;
920
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
921 922
					}
					[] tc_ac.timeout {
923
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
924 925
					}
				}	
926
				
927
				f_checkAeSimuStatus();
928
			
929
				return v_acpAuxIndex;
930
	
931
			}
932
							
933
			/**
934 935
			 * @desc Message exchange for the update of a resource
			 * @param p_requestPrimitive UPDATE request primitive to be used
936 937
			 * @verdict 
			 */
938
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on AeSimu {
939 940 941 942

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

972
				mcaPort.send(m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
973 974
				tc_ac.start;
				alt {
975
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
976
						tc_ac.stop;
977
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
978
					}
979
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
980 981 982 983
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
					}
					[] mcaPort.receive{
984
						tc_ac.stop;
985
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
986 987
					}
					[] tc_ac.timeout {
988
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
989
					}
990 991
				}	
				
992
				f_checkAeSimuStatus();
993
				
994
				return vc_response.primitive.responsePrimitive.primitiveContent;
995
				
996
			}// end f_cse_retrieveResource
997
			
998
			/**
999 1000 1001
			 * @desc Message exchange for the deletion of a resource
			 * @param p_index Resource index of the resource to be deleted
			 * @param p_requestPrimitive DELETE request to be used. If not present default DELETE request will be used
1002 1003
			 * @verdict 
			 */
1004
			function f_cse_deleteResource(in integer p_index, in template (omit) RequestPrimitive p_requestPrimitive := omit) runs on AeSimu {
1005 1006 1007
				var RequestPrimitive v_request;
				
				if(not isvalue(p_requestPrimitive)) {
1008
					v_request := valueof(m_delete(f_getResourceAddress(p_index), f_getOriginator(p_index)));
1009 1010
				} else {
					v_request := valueof(p_requestPrimitive);
1011
				}
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
				
				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_);
					}	
				}	
				
1032
				f_checkAeSimuStatus();
1033 1034 1035 1036
				
			}// end f_cse_deleteResource
			
			/**
1037 1038
			 * @desc Check that a resource is present in the IUT (resourceId is known) by using RETRIEVE operation
			 * @param p_resourceIndex Resource index of the resource to be checked
1039 1040
			 * @return boolean
			 */
1041
			function f_isResourcePresent (integer p_resourceIndex) runs on AeSimu return boolean {
1042 1043
			
				//Check to see if the resource is present or not
1044
				mcaPort.send(m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
1045 1046 1047 1048 1049 1050 1051
				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;
					}
1052 1053 1054 1055 1056
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource: " & f_getResourceAddress(p_resourceIndex) & " not found");
						return false;
					}
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
					[] 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;
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
			}
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known) by using RETRIEVE operation
			 * @param p_resourceIndex Resource index of the resource to be checked
			 * @return boolean
			 */
			function f_isResourcePresentCseSimu (integer p_resourceIndex) runs on CseSimu return boolean {
			
				//Check to see if the resource is present or not
1078
				mccPort.send(m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitive(int2000))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource present: " & f_getResourceAddress(p_resourceIndex));
						return true;
					}
					[] mccPort.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;
1097
			}
1098 1099 1100
			
			/**
			 * @desc Check that a resource is not present in the IUT (resourceId is NOT known)
1101 1102
			 * @param p_parentIndex Index of the parent resource of the resource to be checked
			 * @param p_resourceName Resource name (Hierarchical method is used) of the resource to be checked
1103 1104
			 * @return boolean
			 */
1105
			function f_isResourceNotPresent (integer p_parentIndex, XSD.String p_resourceName) runs on AeSimu return boolean {
1106
			
1107 1108
				log(testcasename() & ":INFO: Hierarchical addressing method is required to check the non presence of the resource");
				
1109
				//Check to see if the resource has NOT been created
1110
				mcaPort.send(m_request(m_retrieve(f_getResourceAddress(p_parentIndex, e_hierarchical) & "/" & p_resourceName, f_getOriginator(p_parentIndex))));
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
				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;
			}
			
			/**
1132
			 * @desc Message exchange for the update of the auxiliar ACP resource
1133 1134 1135
			 * @param p_allowedOperations New allowed operations
			 * @verdict 
			 */
1136
			function f_cse_updateAcpAuxResource (in template (value) AccessControlOperations p_allowedOperations) runs on AeSimu {
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
				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");
1151
						//TODO To save new values
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
					}
					[] 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" );
					}
				}		
				
1162
				f_checkAeSimuStatus();
1163 1164 1165
			}   
			
			/**
1166 1167 1168
			 * @desc Handling of announcement of resources
			 * @param p_from Expected originator of the request primitive
			 * @param p_to Expected receiver of the request primitive
1169 1170 1171
			 * @verdict 
			 */
			 //TODO To finalize this function
1172
			function f_cse_resourceAnnouncementHandler(template XSD.ID p_from := *, template XSD.ID p_to := ?) runs on CseSimu {
1173 1174 1175 1176 1177 1178
				// Local variables
				var MsgIn v_request;
				var ResponsePrimitive v_responsePrimitive;
				
				tc_ac.start;
				alt {
1179
					[] mccPortIn.receive(mw_request(mw_create(p_from, p_to))) -> value v_request {
1180 1181
						tc_ac.stop;
						setverdict(pass, __SCOPE__ & ":INFO: Announcement received");
1182
						//TODO Save resource and generate required attributes
1183
						v_responsePrimitive := f_getCreateResponsePrimitive(v_request.primitive.requestPrimitive.resourceType, v_request.primitive.requestPrimitive);
1184
						mccPortIn.send(m_response(v_responsePrimitive));
1185
						f_checkAttributesToBeSaved(v_request.primitive.requestPrimitive.resourceType, v_request.primitive.requestPrimitive, vc_response.primitive.responsePrimitive);
1186
						f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, v_request.primitive.requestPrimitive.resourceType, vc_remoteCseIndex);					
1187
					}
1188
					[] mccPortIn.receive{
1189 1190 1191 1192 1193 1194 1195
						tc_ac.stop;
						setverdict(fail, __SCOPE__ & ":ERROR: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(fail, __SCOPE__ & ":ERROR:  No announcement received");
					}
				}
1196 1197 1198 1199 1200 1201
				
				f_checkCseSimuStatus();
	
			} //end f_cse_resourceAnnouncementHandler
			
			/**
1202 1203 1204
			 * @desc Message exchange for the announcement of resources
			 * @param p_resourceType ResourceType of the resource to be announced 
			 * @param p_requestPrimitive CREATE request to be used for the announcement
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
			 * @verdict 
			 */
			 //TODO To finalize this function
			function f_cse_announceResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create) runs on CseSimu return integer {
				// Local variables
				var RequestPrimitive v_request;
				var ResponsePrimitive v_responsePrimitive;
				var integer v_resourceIndex := -1;
				
				v_request := f_getCreateRequestPrimitive(f_getAnnouncedResourceType(p_resourceType), p_requestPrimitive, vc_remoteCseIndex);
			
				mccPort.send(m_request(v_request));
				tc_ac.start;
				alt {
1219
					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
1220 1221 1222
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
						f_checkAttributesToBeSaved(p_resourceType, v_request, vc_response.primitive.responsePrimitive);
1223
						v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, f_getAnnouncedResourceType(p_resourceType), vc_remoteCseIndex);
1224
					}
1225
					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
1226 1227 1228
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
					}
1229
					[] mccPort.receive {
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
					}
				}	
				
				f_checkCseSimuStatus();
				
				return v_resourceIndex;
1241
	
1242
			} //end f_cse_announceResource			
1243
    		
1244 1245 1246 1247 1248 1249 1250 1251
			/**
			 * @desc Checking of returned important attributed (in response) in order to save properly internally
			 * @param p_resourceType ResourceType of the resource to be checked
			 * @param p_request Request primitive used for the CRU operation
			 * @param p_response Response primitive received
			 * @verdict 
			 */
			 //Note: This function will be continously extended with necessary attributes/resources
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
			function f_checkAttributesToBeSaved (ResourceType p_resourceType, RequestPrimitive p_request, inout ResponsePrimitive p_response) {
				select (p_resourceType) {
					case (int1) {
						if(isvalue(p_response.primitiveContent.accessControlPolicy) and
								not(ispresent(p_response.primitiveContent.accessControlPolicy.resourceName))) {
							p_response.primitiveContent.accessControlPolicy.resourceName :=  p_request.primitiveContent.accessControlPolicy.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.accessControlPolicy.resourceName)
						}
					}
					case (int2) {
						if(isvalue(p_response.primitiveContent.aE) and
								not(ispresent(p_response.primitiveContent.aE.resourceName))) {
							p_response.primitiveContent.aE.resourceName :=  p_request.primitiveContent.aE.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.aE.resourceName)
						}
					}
					case (int3) {
						if(isvalue(p_response.primitiveContent.container) and
								not(ispresent(p_response.primitiveContent.container.resourceName))) {
							p_response.primitiveContent.container.resourceName :=  p_request.primitiveContent.container.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.container.resourceName)
						}
					}
					case (int4) {
						if(isvalue(p_response.primitiveContent.contentInstance) and
								not(ispresent(p_response.primitiveContent.contentInstance.resourceName))) {
							p_response.primitiveContent.contentInstance.resourceName :=  p_request.primitiveContent.contentInstance.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.contentInstance.resourceName)
						}
					}
					case (int15) {
						if (isvalue(p_response.primitiveContent.pollingChannel) and
								not(ispresent(p_response.primitiveContent.pollingChannel.resourceName))) {
							p_response.primitiveContent.pollingChannel.resourceName :=  p_request.primitiveContent.pollingChannel.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.pollingChannel.resourceName)
						}
					}
					case (int16) {
						if (isvalue(p_response.primitiveContent.remoteCSE) and
								not(ispresent(p_response.primitiveContent.remoteCSE.resourceName))) {
							p_response.primitiveContent.remoteCSE.resourceName :=  p_request.primitiveContent.remoteCSE.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.remoteCSE.resourceName)
						}
					}
					case (int18) {
						if (isvalue(p_response.primitiveContent.schedule) and
								not(ispresent(p_response.primitiveContent.schedule.resourceName))) {
							p_response.primitiveContent.schedule.resourceName :=  p_request.primitiveContent.schedule.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.schedule.resourceName)
						}
					}
					case (int23) {
						if (isvalue(p_response.primitiveContent.subscription) and
								not(ispresent(p_response.primitiveContent.subscription.resourceName))) {
							p_response.primitiveContent.subscription.resourceName :=  p_request.primitiveContent.subscription.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.subscription.resourceName)
						}
					}
					case (int9) {
						if (isvalue(p_response.primitiveContent.group_) and
								not(ispresent(p_response.primitiveContent.group_.resourceName))) {
							p_response.primitiveContent.group_.resourceName :=  p_request.primitiveContent.group_.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.group_.resourceName)
						}
					}
					case else {
						log(__SCOPE__&":WARNING: Resource Type "&int2str(enum2int(p_resourceType))&" not implemented");
					}
1320
				}
1321 1322 1323 1324
    
				// TODO test that if the resource name is returned is the same resource name as used in the create message
			}
		
1325 1326 1327 1328 1329 1330 1331
			/**
			 * @desc Comparison of two URIs
			 * @param p_expectedURIIndex Resource index of the resource for which its URI is to be compared
			 * @param p_receivedURI URI to be compared
			 * @param p_response Response primitive received
			 * @verdict 
			 */
1332
			function f_compareURIs(in integer p_expectedURIIndex, in XSD.ID p_receivedURI) runs on Tester return boolean{
1333 1334
				// Local variables
				var boolean v_matchResult := false;
1335 1336
				var AddressingMethod v_addressingMethod;
				var PrimitiveScope v_primitiveScope;
1337 1338
    			
				if (f_isNonHierarchical(p_receivedURI)) {
1339
					v_addressingMethod := e_nonHierarchical;
1340
				} else if (f_isHierarchical(p_receivedURI)) {
1341
					v_addressingMethod := e_hierarchical;
1342 1343
				}
				if (f_isScopeCseRelative(p_receivedURI)) {
1344
					v_primitiveScope := e_cseRelative;
1345 1346
				}
				if (f_isScopeSpRelative(p_receivedURI)) {
1347
					v_primitiveScope := e_spRelative;
1348
				}
1349
				if (f_isScopeAbsolute(p_receivedURI)) {
1350
					v_primitiveScope := e_absolute;
1351 1352
				}
    			
1353
				if(match(f_getResourceAddress(p_expectedURIIndex, v_addressingMethod, v_primitiveScope), p_receivedURI)) {
1354
					v_matchResult := true;
1355 1356 1357
				} else {
					v_matchResult := false;
				}
1358
							
1359 1360 1361
				return v_matchResult;
    
			} //end f_compareURIs	
1362 1363 1364 1365
			
		}//end group AeSimu
			
		group CseSimuFunctions {
1366 1367 1368

			group NotificationFunctions { 
				
1369 1370 1371 1372
				/**
				 * @desc Handling message exchange for the subscription verification
				 * @param p_responseStatusCode Response Status Code to be used for the response to the verification request
				 * @verdict 
1373
				 */
Naum Spaseski's avatar
Naum Spaseski committed
1374
				function f_cse_notifyProcedure_subscriptionVerificationHandler(in ResponseStatusCode p_responseStatusCode := int2000) runs on AeSimu {
1375 1376 1377
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					var template Notification v_notificationRequest := mw_contentNotificationVerification;
1378
    				
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
					//Preparation of expected Notification verification
					//TODO To add checks for creator and subscription reference
					//v_notificationRequest.creator := p_creator; TODO To check what address format is to be expected
					//Some participants use SP relative UNSTRUCTURED
					//v_notificationRequest.subscriptionReference := "I Don't know which URI is expected"; // TODO mandatory parameter 
    			
					//Preparation of Notification response to be sent
					v_responsePrimitive := valueof(m_responseNotification(p_responseStatusCode, omit));
    	
					tc_ac.start;
					alt {
1390
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(v_notificationRequest))) -> value vc_request {
1391 1392 1393
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Notification received");
						}
1394
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
1395 1396 1397
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: Notification received but verificationRequest isn't set to TRUE");							
						}
1398
						[] mcaPortIn.receive{
1399 1400
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: unexpected message received");
1401
							stop;
1402 1403 1404
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR:  No notification received");
1405
							stop;
1406 1407
						}
					}
1408
						
1409
					v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
1410
					if(getverdict == pass) {
1411 1412 1413 1414 1415 1416
						mcaPortIn.send(m_httpResponse(v_responsePrimitive));
					} else {
						v_responsePrimitive.responseStatusCode := int4000; 
						mcaPortIn.send(m_httpResponse(v_responsePrimitive));
					}
					
1417
					//mcaPort.send(m_response(v_responsePrimitive));	// TODO have to be deleted
1418
        
1419 1420
				} //end f_subscriptionVerificationHandler
    		
1421 1422 1423 1424 1425
				/**
				 * @desc Handling message exchange for the notification procedure
				 * @param p_primitiveContent Expected primitiveContent in the notification
				 * @verdict 
				 */
1426
				function f_cse_notifyProcedure_representationHandler(template PrimitiveContent p_primitiveContent) runs on AeSimu {
1427
					// Local variables
1428 1429
					var ResponsePrimitive v_responsePrimitive;
					
1430 1431
					tc_ac.start;
					alt {
1432
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
1433
							tc_ac.stop;
1434
							if(f_check_notificationContent(vc_request.primitive.requestPrimitive, p_primitiveContent)){
1435 1436 1437 1438
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
1439
							}
1440 1441 1442 1443
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2001, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							mcaPortIn.send(m_response(v_responsePrimitive));
1444
						}
1445
						[] mcaPortIn.receive{
1446 1447 1448 1449 1450 1451 1452
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
1453
	    		    	
1454 1455
				} //end f_cse_notifyProcedure_representationHandler
	    		
1456 1457 1458 1459 1460
				/**
				 * @desc Handling message exchange for the notification procedure (aggregatedNotification)
				 * @param p_primitiveContent Expected primitiveContent in the notification
				 * @verdict 
				 */
1461
				function f_cse_notifyProcedure_aggregatedNoficationHandler(template PrimitiveContent p_primitiveContent,in integer p_numberOfAggregatedNotification) runs on AeSimu {
1462
					// Local variables
1463 1464
					var ResponsePrimitive v_responsePrimitive;
					var integer v_notificationsReceived := 0;
1465 1466 1467
    
					tc_ac.start;
					alt {
1468
						[] mcaPortIn.receive(mw_request(mw_notifyAggregatedNotification)) -> value vc_request {
1469
							tc_ac.stop;
1470 1471
							if(p_numberOfAggregatedNotification == lengthof(vc_request.primitive.requestPrimitive.primitiveContent.aggregatedNotification.notification_list)){
								if(f_check_notificationContent(vc_response.primitive.requestPrimitive, p_primitiveContent)){
1472 1473 1474 1475 1476
									setverdict(pass, __SCOPE__ & ": Notification received");
								}
								else{
									setverdict(fail, __SCOPE__ & ": Notification received but the content doesn't match");
								}
1477
							}
1478 1479 1480
							else {
								setverdict(fail, __SCOPE__ & ": Number of Notification in Aggregatednotification isn't right");
							}
1481 1482 1483 1484 1485
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2001, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							mcaPortIn.send(m_response(v_responsePrimitive));
						}
1486
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
							tc_ac.stop;
							if(f_check_notificationContent(vc_request.primitive.requestPrimitive, p_primitiveContent)){
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
							}
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2001, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							mcaPortIn.send(m_response(v_responsePrimitive));
							v_notificationsReceived := v_notificationsReceived + 1;
							if(v_notificationsReceived < p_numberOfAggregatedNotification) {
								tc_ac.start;
								repeat;
							}
1503
						}