OneM2M_Functions.ttcn 83.8 KB
Newer Older
1 2 3 4 5 6 7 8
/**
 *  Copyright Notification
 *  No part of this document may be reproduced, in an electronic retrieval system or otherwise, except as authorized by written permission.
 *  The copyright and the foregoing restriction extend to reproduction in all media.
 *  © 2016, oneM2M Partners Type 1 (ARIB, ATIS, CCSA, ETSI, TIA, TSDSI, TTA, TTC).
 *  All rights reserved.
 *  
 *  @author     ETSI
9 10
 *  @version    $URL: https://oldforge.etsi.org/svn/oneM2M/branches/Release1/ttcn/LibOneM2M/OneM2M_Functions.ttcn $
 *              $Id: OneM2M_Functions.ttcn 347 2017-08-11 08:48:20Z reinaortega $
11 12 13 14 15 16 17 18 19 20 21
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from XSD all;
	import from OneM2M_Templates all;
	import from OneM2M_Types all;//{type XSD.ID};
	import from OneM2M_TypesAndValues all;
	import from OneM2M_TestSystem all;
	import from OneM2M_Pixits all;
22
	import from OneM2M_Pics all;
23 24 25
//	import from OneM2M_AdditionalTypes all;
	
	
26 27
	group ConfigFunctions {
		
28 29 30 31
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
		function f_cf01Up() runs on CseTester {
32
				
33
			// Variables
34 35
			vc_config := e_cf01;	
			
36 37 38 39
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
40
			activate(a_cse_cf01());
41
				
42
			// Connect
43
						
44
			//Initialze the IUT
45
							
46
		} // end f_cf01Up
47
		
48 49 50
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
51
		function f_cf02Up() runs on CseTester {
52
				
53
			// Variables
54 55
			vc_config := e_cf02;
				
56 57 58 59 60
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:mccPort, system:mccPort);
			map(self:acPort, system:acPort);
			activate(a_default());
61
			activate(a_cse_cf02());
62
				
63
			// Connect
64
					
65
			//Initialze the IUT
66
							
67
		} // end f_cf02Up
68
		
69 70 71 72
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
		function f_cf03Up() runs on AeTester {
73 74
		
			// Variables
75 76
			vc_config := e_cf03;
			
77 78 79 80
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
81
			activate(a_ae_cf03());
82 83 84 85 86 87 88
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
		function f_cf04Up() runs on CseTester {

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

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

		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
		function f_cfCseTesterDown() runs on CseTester {
		
			if(vc_config == e_cf01) {
				f_cf01Down()
			} else if (vc_config == e_cf02){
				f_cf02Down()
			} 
		}
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
		function f_cfAeTesterDown() runs on AeTester {
		
			if(vc_config == e_cf03) {
				f_cf03Down()
			} 
		}			
131 132 133
		/**
		 * @desc Ports unmapping
		 * @verdict 
134
		 */
135
		function f_cf01Down() runs on CseTester {
136
		
137
			unmap(self:mcaPort, system:mcaPort);
138 139
			unmap(self:acPort, system:acPort);
		}	
140 141 142 143
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
144
		function f_cf02Down() runs on CseTester {
145
		
146
			unmap(self:mcaPort, system:mcaPort);
147
			unmap(self:mccPort, system:mccPort);
148
			unmap(self:acPort, system:acPort);
149
		}		
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
		/**
		 * @desc Ports unmapping for Config 03
		 */
		function f_cf03Down() runs on AeTester {
			
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
		}
		
		/**
		 * @desc Ports unmapping for Config 04
		 */
		function f_cf04Down() runs on CseTester {
	
			unmap(self:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
		}
		
168
	}//end group configFunctions
169
	
170
	group CseFunctions {
171
	
172
		group PreambleFunctions {
173 174 175 176 177 178 179 180

			/**
			 * @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 
			 */
			function f_cse_preamble_createAcpAux(in template (value) XSD.String p_acpName := c_acpAuxName, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer {//c_CRUDNDi
181
			
182
				return f_cse_createAccessControlPolicyAux(p_acpName, -, p_allowedOperations);
183
			
184 185
			}

186
	
187 188 189 190 191 192 193
			/**
			 * @desc Creation of auxiliar resources ACP and AE for correct execution of the test case
			 * @param p_allowedOperations Allowed operations for the auxiliar AE resource
			 * @return Internal AE resource index
			 * @verdict 
			 */
			function f_cse_preamble_registerAe(template (omit) AcpType p_accessControlPolicyIDs := omit, in template (omit) PoaList p_poaList := omit) runs on CseTester return integer {//c_CRUDNDi
194
			
195 196 197
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
198
								
199
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
200 201
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
202 203
				
				mcaPort.send(m_request(v_request));
204
				
205 206 207 208
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
209 210 211 212 213
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
214
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
215
							
216 217
							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)));
218 219
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
220 221
							}
						}
222 223 224
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
225
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
226 227 228 229
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
230
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
231
						stop;
232
					};
233
					[] tc_ac.timeout {
234
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
235 236 237
						stop;
					}
				}	
238 239
				
				f_checkCseTesterStatus();
240
				return vc_aeAuxIndex;
241
			
242
			}
243
			
244 245 246 247 248 249 250
			/**
			 * @desc Creation of auxiliar resources ACP and AE for correct execution of the test case
			 * @param p_allowedOperations Allowed operations for the auxiliar AE resource
			 * @return Internal AE resource index
			 * @verdict 
			 */
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer {//c_CRUDNDi
251
			
252 253 254 255
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
				var integer v_acpAuxIndex := -1;
256
			
257 258 259 260
				if(PICS_ACP_SUPPORT){
					v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
					vc_acpAuxIndex := v_acpAuxIndex;
				}
261
				
262 263 264
				if(v_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}, -));
265
					
266 267
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
268
					
269 270 271 272 273 274 275 276 277
					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 {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
278 279 280
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
281
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
282
							
283 284
							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)));
285 286 287 288 289
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
290 291
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
292
						tc_ac.stop;
293
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
294 295 296 297
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
298
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
299 300 301
						stop;
					}
					[] tc_ac.timeout {
302
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
303 304 305
						stop;
					}
				}	
306 307
				
				f_checkCseTesterStatus();
308
				return vc_aeAuxIndex;
309
			
310
			}
311 312 313
			
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on CseTester return integer {//c_CRUDNDi
			
314
				var integer v_serviceSubscribedAppRuleIndex := -1;
315
	
316
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
317
				
318
				return v_serviceSubscribedAppRuleIndex;
319
			
320
			}
321 322
			
			function f_cse_preamble_subscriptionVerification(out CseTester p_notifyHandler,in integer p_aeIndex, inout integer p_ae2Index, inout template RequestPrimitive p_createRequestPrimitive,in ResourceType p_resourceType, in ResponseStatusCode p_responseStatusCode := int2001) runs on CseTester {
323 324
				if(p_resourceType == int23){
					p_notifyHandler := CseTester.create("NotifyHandler") alive;
325 326 327
					p_ae2Index := f_cse_createResource(int2, m_createAe(PX_APP_ID, -, PX_AE2_ID_STEM, "MyAe2", {f_getAnnouncementTargetPoA("HTTP", PX_AE2_ADDRESS, "")}), -1); // AE2 is registred
					if(ischosen(p_createRequestPrimitive.primitiveContent.subscription)){		//this condition is necessary for Subscription TCs where notification URI is set in m_createSubscriptionAdvanced
						p_createRequestPrimitive.primitiveContent.subscription.notificationURI := {f_getResourceAddress(p_ae2Index)}; 
328
					}
329
					p_notifyHandler.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_aeIndex, p_responseStatusCode));
330 331
				}
			}
332
		
333
		}//end group preambleFunctions
334 335 336
		
		group PostambleFunctions {
	
337 338 339 340 341 342 343 344
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
			function f_cse_postamble_deleteResources() runs on CseTester {
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
345
				
346
				if (PX_RUN_POSTAMBLE) {
347
					
348 349 350 351
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
352
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
353 354
						
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);
355

356
						mcaPort.send(m_request(v_request));
357
						
358 359 360 361
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
362
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
363 364 365
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
366
								log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
367 368
							}
							[] tc_ac.timeout {
369
								log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
370 371
							}	
						}	
372
						
373 374
					}
				}
375
							
376 377
				f_cse_postamble_default();
			}
378
			
379 380 381 382 383
			/**
			 * @desc Default postamble
			 * @verdict 
			 */
			function f_cse_postamble_default() runs on CseTester {
384
			}
385 386
			
			function f_is_component_done(in CseTester p_notifyHandler) runs on CseTester {
387
			
388 389 390 391 392 393
				tc_ac.start(10.0);
				alt {
					[] p_notifyHandler.done {
					tc_ac.stop;
					}
					[] tc_ac.timeout {
394
						setverdict(inconc, __SCOPE__ & "INFO: Notify verification not received");
395 396 397
					}
				}
			} //end f_is_component_done
398 399
			
			
400
		}//end group postambleFunctions
401 402 403
		
		group HelpingFunctions {
	
404 405 406 407 408 409 410 411 412
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive Template request primitive
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on CseTester return integer {
413
			
414 415 416
				var MsgIn v_response;
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
417
				
418
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
419
			
420 421 422 423 424
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
425 426 427
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
						f_checkAttributesToBeSaved(p_resourceType, v_request, v_response.primitive.responsePrimitive);
						v_resourceIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, p_resourceType, p_parentIndex);
428 429 430
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
431
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
432 433 434
					}
					[] mcaPort.receive {
						tc_ac.stop;
435
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
436 437
					}
					[] tc_ac.timeout {
438
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
439 440
					}
				}	
441 442 443
				
				f_checkCseTesterStatus();
				
444
				return v_resourceIndex;
445
		
446
			}
447
		
448 449 450 451 452 453 454
			/**
			 * @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 
			 */
455
			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 CseTester return integer{				var RequestPrimitive v_request;
456 457
				var MsgIn v_response;
				var integer v_acpAuxIndex := -1;
458
				
459
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
460
				
461 462
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
463 464 465 466 467
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
468 469 470
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
						f_checkAttributesToBeSaved(int1, v_request, v_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int1);
471 472 473 474
						vc_acpAuxIndex := v_acpAuxIndex;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
475
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
476 477 478
					}
					[] mcaPort.receive {
						tc_ac.stop;
479
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
480 481
					}
					[] tc_ac.timeout {
482
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
483 484
					}
				}	
485 486 487
				
				f_checkCseTesterStatus();
			
488
				return v_acpAuxIndex;
489
	
490
			}
491 492
				
				
493 494 495 496 497 498 499
			/**
			 * @desc Creation of the auxiliar Container resource
			 * @param p_parentIndex Internal resource index which indicates the parent of the Container resource to be created
			 * @return Internal resource index of the created Container resource
			 * @verdict 
			 */
			function f_cse_createContainerResourceAux (integer p_parentIndex := -1) runs on CseTester return integer {
500
			
501 502 503
				var RequestPrimitive v_request;
				var integer v_acpAuxIndex := -1;
				var integer v_containerResourceIndex := -1;
504
				
505
				v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_acpName := c_acpAuxName);//"MyAcp_2"
506
				
507
				v_request := valueof(m_createContainerBase);
508 509 510
				v_request.primitiveContent.container.accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)};
				v_request.primitiveContent.container.resourceName := "MyContainerAux";
				
511
				v_containerResourceIndex := f_cse_createResource(int3, v_request, p_parentIndex);
512
				
513
				return v_containerResourceIndex;		
514
		
515
			}
516
			
517 518 519 520 521 522 523 524 525 526 527 528 529
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on CseTester {
				var MsgIn v_response;

				mcaPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
530
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
531 532 533
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value v_response {
						tc_ac.stop;
534
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
535 536 537
					}
					[] mcaPort.receive{
						tc_ac.stop;
538
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
539 540
					}
					[] tc_ac.timeout {
541
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
542 543
					}
				}	
544 545 546
				
				f_checkCseTesterStatus();
				
547
			}// end f_cse_updateResource
548
			
549
			/**
550 551
			 * @desc 
			 * @param p_resourceIndex
552 553
			 * @verdict 
			 */
554 555 556 557
			function f_cse_retrieveResource(integer p_resourceIndex) runs on CseTester return PrimitiveContent{
				var MsgIn v_response;

				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
558 559
				tc_ac.start;
				alt {
560
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
561
						tc_ac.stop;
562
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
563
					}
564 565 566 567 568
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value v_response {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
					}
					[] mcaPort.receive{
569
						tc_ac.stop;
570
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
571 572
					}
					[] tc_ac.timeout {
573
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
574
					}
575 576 577 578 579 580 581
				}	
				
				f_checkCseTesterStatus();
				
				return v_response.primitive.responsePrimitive.primitiveContent;
				
			}// end f_cse_retrievingResource
582
			
583 584 585 586 587 588 589 590 591
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
			function f_cse_deleteResource(in integer p_index, in template (omit) RequestPrimitive p_requestPrimitive := omit) runs on CseTester {
				var RequestPrimitive v_request;
				
				if(not isvalue(p_requestPrimitive)) {
592
					v_request := valueof(m_delete(f_getResourceAddress(p_index), f_getOriginator(p_index)));
593 594
				} else {
					v_request := valueof(p_requestPrimitive);
595
				}
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
				
				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_);
					}	
				}	
				
				f_checkCseTesterStatus();
				
			}// end f_cse_deleteResource
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known)
			 * @param p_resourceIndex Resource index 
			 * @return boolean
			 */
			function f_isResourcePresent (integer p_resourceIndex) runs on CseTester return boolean {
			
				//Check to see if the resource is present or not
				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int2000))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource present: " & f_getResourceAddress(p_resourceIndex));
						return true;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitive(?, -))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						return false;
					}
				}	
				return false;
647
			}
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
			
			/**
			 * @desc Check that a resource is not present in the IUT (resourceId is NOT known)
			 * @param p_parentIndex Index of the parent resource
			 * @param p_resourceName Resource name (Hierarchical method is used)
			 * @return boolean
			 */
			function f_isResourceNotPresent (integer p_parentIndex, XSD.String p_resourceName) runs on CseTester return boolean {
			
				log(testcasename() & ":INFO: Hierarchical method is required to check the non presence of the resource");
				vc_addressingMethod := e_hierarchical;
				//Check to see if the resource has NOT been created
				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_parentIndex) & "/" & p_resourceName, f_getOriginator(p_parentIndex))));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource not present");
						vc_addressingMethod := PX_ADDRESSING_METHOD;
						return true;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitive(?))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						vc_addressingMethod := PX_ADDRESSING_METHOD;
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						vc_addressingMethod := PX_ADDRESSING_METHOD;
						return false;
					}
				}	
				return false;
			}
			
			/**
			 * @desc Update of the auxiliar ACP resource
			 * @param p_allowedOperations New allowed operations
			 * @verdict 
			 */
			function f_cse_updateAcpAuxResource (in template (value) AccessControlOperations p_allowedOperations) runs on CseTester {
				var RequestPrimitive v_request;
				
				v_request := valueof(m_updateAcpBase);
				
				v_request.to_ := f_getResourceAddress(vc_acpAuxIndex);
				v_request.from_ := f_getOriginator(vc_acpAuxIndex);
				v_request.primitiveContent.accessControlPolicy.privileges.accessControlRule_list := {valueof(m_createAcr(PX_ACOR, p_allowedOperations))};
							
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK))  {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: " & v_request.to_ & " resource updated successfuly");
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while updating " & v_request.to_ & " resource");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating " & v_request.to_ & " resource" );
					}
				}		
				
				f_checkCseTesterStatus();
			}   
			
			/**
			 * @desc Function to handle announcement of resources
			 * @param p_from
			 * @param p_to
			 * @verdict 
			 */
			 //TODO To finalize this function
			function f_cse_resourceAnnouncementHandler(template XSD.ID p_from := *, template XSD.ID p_to := ?) runs on CseTester {
				// Local variables
				var MsgIn v_request;
				var ResponsePrimitive v_responsePrimitive;
				
				map(self:mccPort, system:mccPort);
				map(self:acPort, system:acPort);
731

732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_request(mw_create(p_from, p_to))) -> value v_request {
						tc_ac.stop;
						setverdict(pass, __SCOPE__ & ":INFO: Announcement received");
						v_responsePrimitive := f_getCreateResponsePrimitive(v_request.primitive.requestPrimitive.resourceType, v_request.primitive.requestPrimitive);
						mcaPort.send(m_response(v_responsePrimitive)); 						
					}
					[] mcaPort.receive{
						tc_ac.stop;
						setverdict(fail, __SCOPE__ & ":ERROR: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(fail, __SCOPE__ & ":ERROR:  No announcement received");
					}
				}
748
	
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
				unmap(self:mccPort, system:mccPort);
				unmap(self:acPort, system:acPort); 

			} //end f_cse_resourceAnnouncementHandler			
    		
			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");
					}
822
				}
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
    
				// TODO test that if the resource name is returned is the same resource name as used in the create message
			}
		
			function f_compareURIs(in integer p_expectedURIIndex, in XSD.ID p_receivedURI) runs on CseTester return boolean{
				// Local variables
				var boolean v_matchResult := false;
    			
				if (f_isNonHierarchical(p_receivedURI)) {
					vc_addressingMethod := e_nonHierarchical;
				} else if (f_isHierarchical(p_receivedURI)) {
					vc_addressingMethod := e_hierarchical;
				}
				if (f_isScopeCseRelative(p_receivedURI)) {
					vc_primitiveScope := e_cseRelative;
				}
				if (f_isScopeSpRelative(p_receivedURI)) {
					vc_primitiveScope := e_spRelative;
841
				}
842 843 844 845 846
				if (f_isScopeAbsolute(p_receivedURI)) {
					vc_primitiveScope := e_absolute;
				}
    			
				if(match(f_getResourceAddress(p_expectedURIIndex), p_receivedURI)) {
847
					v_matchResult := true;
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
				} else {
					v_matchResult := false;
				}
				
				vc_primitiveScope := PX_PRIMITIVE_SCOPE;
				vc_addressingMethod := PX_ADDRESSING_METHOD;
    						
				return v_matchResult;
    
			} //end f_compareURIs	

			group NotificationFunctions { 
				
				function f_cse_notifyProcedure_subscriptionVerificationHandler(in integer p_creatorIndex, in ResponseStatusCode p_responseStatusCode := int2001) runs on CseTester {
					// Local variables
					var MsgIn v_request;
					var ResponsePrimitive v_responsePrimitive;
					var template Notification v_notificationRequest := mw_contentNotificationVerification;
    			
					map(self:mcaPort, system:mcaPort);
					map(self:acPort, system:acPort);
    			
					//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 {
881
						[] mcaPort.receive(mw_request(mw_notify(v_notificationRequest))) -> value v_request {
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							v_responsePrimitive.requestIdentifier := v_request.primitive.requestPrimitive.requestIdentifier;
//							if(f_isHierarchical(v_request.primitive.requestPrimitive.primitiveContent.notification.creator)) {
//								setverdict(fail, __SCOPE__ & ": Creator cannot contain a hierarchical address");
//								v_responsePrimitive.responseStatusCode := int4000;
//							}
//							if(f_compareURIs(p_creatorIndex, v_request.primitive.requestPrimitive.primitiveContent.notification.creator)) {
//								setverdict(pass, __SCOPE__ & ": Creator set to originator of the subscription creation primitive");
//							} else {
//								setverdict(fail, __SCOPE__ & ": Creator not set to originator of the subscription creation primitive");
//								v_responsePrimitive.responseStatusCode := int4000;
//							}
							mcaPort.send(m_httpResponse(v_responsePrimitive)); 						
						}
						[] mcaPort.receive(mw_request(mw_notify(mw_contentNotification(?)))) -> value v_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: Notification received but verificationRequest isn't set to TRUE");							
						}
						[] mcaPort.receive{
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR:  No notification received");
						}
					}
    	
					//mcaPort.send(m_response(v_responsePrimitive));	// TODO have to be deleted
    
					unmap(self:mcaPort, system:mcaPort);
					unmap(self:acPort, system:acPort); 
    
				} //end f_subscriptionVerificationHandler
    		
				function f_cse_notifyProcedure_representationHandler(template PrimitiveContent p_primitiveContent) runs on CseTester {
					// Local variables
					var MsgIn v_request;
	    	
					map(self:mcaPort, system:mcaPort);
					map(self:acPort, system:acPort);
	    	
					tc_ac.start;
					alt {
						[] mcaPort.receive(mw_request(mw_notify(mw_contentNotification(?)))) -> value v_request {
							tc_ac.stop;
							if(f_check_notificationContent(v_request.primitive.requestPrimitive, p_primitiveContent)){
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
								mcaPort.send(m_response(valueof(m_responseNotification(int2001))));
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
934 935
							}
						}
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
						[] mcaPort.receive{
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
	    	
	    		
					unmap(self:mcaPort, system:mcaPort);
					unmap(self:acPort, system:acPort); 
	    	
				} //end f_cse_notifyProcedure_representationHandler
	    		
				function f_cse_notifyProcedure_aggregatedNoficationHandler(template PrimitiveContent p_primitiveContent,in integer p_numberOfAggregatedNotification) runs on CseTester {
					// Local variables
					var MsgIn v_response;
    
					map(self:mcaPort, system:mcaPort);
					map(self:acPort, system:acPort);
    
					tc_ac.start;
					alt {
						[] mcaPort.receive(mw_request(mw_aggregatedNotifyBase)) -> value v_response {
							tc_ac.stop;
							if(p_numberOfAggregatedNotification == lengthof(v_response.primitive.requestPrimitive.primitiveContent.aggregatedNotification.notification_list)){
								if(f_check_notificationContent(v_response.primitive.requestPrimitive, p_primitiveContent)){
									setverdict(pass, __SCOPE__ & ": Notification received");
								}
								else{
									setverdict(fail, __SCOPE__ & ": Notification received but the content doesn't match");
								}
969
							}
970 971 972 973 974 975 976 977 978 979 980
							else {
								setverdict(fail, __SCOPE__ & ": Number of Notification in Aggregatednotification isn't right");
							}
						}
						[] mcaPort.receive{
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ": Error, unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ": No notification received");
						}
981
					}
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    	
					unmap(self:mcaPort, system:mcaPort);
					unmap(self:acPort, system:acPort); 
    
				} //end f_cse_notifyProcedure_aggregatedNotificationHandler
	    		
				function f_cse_notifyProcedure_subscriptionDeletionHandler( template PrimitiveContent p_primitiveContent) runs on CseTester {
					var MsgIn v_response;
	
					map(self:mcaPort, system:mcaPort);
					map(self:acPort, system:acPort);
					
					tc_ac.start;
					alt {
						[] mcaPort.receive(mw_request(mw_notify(mw_contentNotification(?)))) -> value v_response {
							tc_ac.stop;
							mcaPort.send(m_response(valueof(m_responseNotification(int2001))));
							if(not(match(v_response.primitive.requestPrimitive.primitiveContent.notification.subscriptionDeletion, true))) {
								setverdict(fail, __SCOPE__ & ":ERROR: subscriptionDeletion attribute have to be set to TRUE");
							}
							if(f_check_notificationContent(v_response.primitive.requestPrimitive, p_primitiveContent)){
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
							}
						}
						[] mcaPort.receive{
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
1016
					}
1017 1018 1019
					
					unmap(self:mcaPort, system:mcaPort);
					unmap(self:acPort, system:acPort);  
1020
	
1021 1022 1023 1024 1025
				} //end f_cse_notifyProcedure_subscriptionDeletionHandler  
				
				function f_cse_notifyProcedure_noNotificationHandler() runs on CseTester {
					// Local variables
					var MsgIn v_response;
1026
	
1027 1028
					map(self:mcaPort, system:mcaPort);
					map(self:acPort, system:acPort);
1029
		
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
					tc_ac.start(10.0);
					alt {
						[] mcaPort.receive(mw_request(mw_notify(mw_contentNotification(?)))) -> value v_response {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ": Error, Non expected notification received");
						}
						[] tc_ac.timeout {
							setverdict(pass, __SCOPE__ & ": No notification received");
						}
					}
	
					unmap(self:mcaPort, system:mcaPort);
					unmap(self:acPort, system:acPort); 
	
				} //end f_cse_notifyProcedure_noNotification Handler
				
				function f_check_notificationContent(in RequestPrimitive p_requestPrimitive, template PrimitiveContent p_primitiveContent) runs on CseTester return boolean{
					// Local variables
					var boolean v_matchResult := false;
					var integer i;
					var integer v_numberOfAggregatedNotification;
    	
					if (ischosen(p_primitiveContent.aE)){
						if(ischosen(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource)) {
							v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.aE, p_primitiveContent.aE)
						}
						else if(ischosen(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.responsePrimitive)) {
							v_matchResult :=match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.responsePrimitive.primitiveContent.aE, p_primitiveContent.aE)
						}
						else if (ischosen(p_requestPrimitive.primitiveContent.aggregatedNotification)) {
							v_matchResult := true;
							v_numberOfAggregatedNotification := lengthof(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list);
							for(i := 0; i< v_numberOfAggregatedNotification; i := i + 1){
								if(ischosen(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.resource)) {
									if(not (match(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.resource.aE, p_primitiveContent.aE))){
										v_matchResult := false;
									}
								}
								else if(ischosen(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.responsePrimitive)) {
									if(not (match(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.responsePrimitive.primitiveContent.aE, p_primitiveContent.aE))){
										v_matchResult := false;
									}
								}						
							}
							if (i == 0){
								v_matchResult := false;
							}
						}
1078
    
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
					}
    	
					if (ischosen(p_primitiveContent.container)){
						if(ischosen(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource)) {
							v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.container, p_primitiveContent.container)
						}
						else if(ischosen(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.responsePrimitive)) {
							v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.responsePrimitive.primitiveContent.container, p_primitiveContent.container)
						}
					}
    	
					return v_matchResult;
1091