OneM2M_Functions.ttcn 39.4 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
 *  @version    $URL: https://forge.etsi.org/svn/oneM2M/branches/Release1/ttcn/LibOneM2M/OneM2M_Functions.ttcn $
10
 *              $Id: OneM2M_Functions.ttcn 183 2016-11-25 13:31:34Z reinaortega $
11 12 13 14 15 16 17 18 19 20 21 22
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from LibCommon_Time {modulepar all;}
	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;
23
	import from OneM2M_Pics all;
24 25 26 27
//	import from OneM2M_AdditionalTypes all;
	
	
	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 36 37 38
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
39
			activate(a_cse_cf01());
40
    			
41
			// Connect
42
    						
43
			//Initialze the IUT
44
    						
45
		} // end f_cf01Up
46
		
47
		function f_cf02Up() runs on CseTester {
48 49 50 51 52 53 54 55
    			
			// Variables
    			
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:mccPort, system:mccPort);
			map(self:acPort, system:acPort);
			activate(a_default());
56
			activate(a_cse_cf02());
57 58 59 60 61 62
    			
			// Connect
    						
			//Initialze the IUT
    						
		} // end f_cf02Up
63
		
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
		function f_cf03Up() runs on CseTester {
		
			// Variables
		
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
			activate(a_cse_cf01());
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
80 81 82
		/**
		 * @desc Ports unmapping
		 * @verdict 
83
		 */
84 85
		function f_cf01Down() runs on CseTester {
    	
86
			unmap(self:mcaPort, system:mcaPort);
87 88 89
			unmap(self:acPort, system:acPort);
			//stop;
		}	
90 91 92
    		
		function f_cf02Down() runs on CseTester {
    	
93
			unmap(self:mcaPort, system:mcaPort);
94
			unmap(self:mccPort, system:mccPort);
95 96
			unmap(self:acPort, system:acPort);
			//stop;
97
		}		
98 99
    	
	}//end group configFunctions
100
	
101 102
	group cseFunctions {
	
103 104 105 106 107 108 109 110 111 112 113 114 115 116
		group preambleFunctions {

			/**
			 * @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
    		
				return f_cse_createAccessControlPolicyAux(p_acpName, p_allowedOperations);
    		
			}

117
    
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 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
    		
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
    			    			
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
				v_request.to_ := f_getResourceAddress();
				
				mcaPort.send(m_request(v_request));
    			
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
						log("Preamble: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional)) {
							vc_aeAux := v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional;
    						
							v_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent);
							vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_aeAuxIndex};
    						
							if(ispresent(vc_aeAux.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(vc_aeAux.aE_ID)));
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						};
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, "Preamble: Error while registering application");
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, "Preamble: Unexpected message received");
						stop;
					}
					[] tc_ac.timeout {
						setverdict(inconc, "Preamble: No answer while registering resource");
						stop;
					}
				}	
    			
				return v_aeAuxIndex;
    		
			}
    		
			/**
			 * @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
    		
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
				var integer v_acpAuxIndex := -1;
    		
				if(PICS_ACP_SUPPORT){
					v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
					vc_acpAuxIndex := v_acpAuxIndex;
				}
    			
				if(v_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}, -));
194
    				
195 196
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
197
    				
198 199 200 201 202 203 204 205 206 207 208 209
					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;
						log("Preamble: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional)) {
							vc_aeAux := v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional;
210
    						
211 212
							v_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent);
							vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_aeAuxIndex};
213
    						
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
							if(ispresent(vc_aeAux.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(vc_aeAux.aE_ID)));
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, "Preamble: Error while registering application");
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, "Preamble: Unexpected message received");
						stop;
					}
					[] tc_ac.timeout {
						setverdict(inconc, "Preamble: No answer while registering resource");
						stop;
					}
				}	
    			
				return v_aeAuxIndex;
    		
			}
    		
			//Added by @Naum
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer {//c_CRUDNDi
    		
				var MsgIn v_response;
				var integer v_serviceSubscribedAppRuleIndex := -1;
				var RequestPrimitive v_request;
247
    
248
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
249
    			
250 251 252
				return v_serviceSubscribedAppRuleIndex;
    		
			}
253
    		
254 255 256 257 258 259 260 261 262 263
			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 ) runs on CseTester {
				if(p_resourceType == int23){
					p_notifyHandler := CseTester.create("NotifyHandler") alive;
					p_ae2Index := f_cse_createResource(int2, m_createAe(PX_APP_ID, -, PX_AE_ID_STEM, "MyAe2", {"http://" & PX_TESTER_ADDRESS & "/"}), -1); // AE2 is registred
					if(ischosen(p_createRequestPrimitive.primitiveContent.any_1[0].Subscription_optional)){		//this condition is necessary for Subscription TCs where notification URI is set in m_createSubscriptionAdvanced
						p_createRequestPrimitive.primitiveContent.any_1[0].Subscription_optional.notificationURI := {f_getResourceAddress(p_ae2Index)}; 
					}
					p_notifyHandler.start(f_subscriptionVerificationHandler(f_getResourceAddress(p_aeIndex)));
				}
			}
264
    	
265
		}//end group preambleFunctions
266
    	
267
		group postambleFunctions {
268
    
269 270 271 272 273 274 275 276 277 278 279
			/**
			 * @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 MsgIn v_response;
				var RequestPrimitive v_request;
    			
				if (PX_RUN_POSTAMBLE) {
280
    				
281 282 283 284 285
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
						v_request := valueof(m_deleteRequest(v_resourceAddress));
286
    					
287 288 289 290 291 292
						if(PX_FROM_IS_AE_ID){
							if(ischosen(vc_resourcesList[vc_resourcesIndexToBeDeleted[i]].resource.any_1[0].AE_optional)) {	
								v_request.from_ := vc_resourcesList[vc_resourcesIndexToBeDeleted[i]].resource.any_1[0].AE_optional.aE_ID;
							}
						}
						mcaPort.send(m_request(v_request));
293
    					
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
								log("Postamble: AE Resource deleted");
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
								log("Postamble: Error while deleting resource");
							}
							[] tc_ac.timeout {
								log("Postamble: No answer while deleting resource");
							}	
						}	
					}
				}
310
    						
311 312
				f_cse_postamble_default();
			}
313 314 315 316 317 318
    		
			/**
			 * @desc Default postamble
			 * @verdict 
			 */
			function f_cse_postamble_default() runs on CseTester {
319
			}
320 321 322 323 324 325 326 327 328 329 330 331 332
			
			function f_is_component_done(in CseTester p_notifyHandler) runs on CseTester {
    		
				tc_ac.start(10.0);
				alt {
					[] p_notifyHandler.done {
					tc_ac.stop;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": Notify verification not received");
					}
				}
			} //end f_is_component_done
333 334
    		
    		
335
		}//end group postambleFunctions
336
    	
337
		group helpingFunctions {
338
    
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
			/**
			 * @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 {
    		
				var MsgIn v_response;
				var RequestPrimitive v_request;
				var XSD.ID v_resourceId;
				var integer v_resourceIndex := -1;
    			
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
    		
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
						setverdict(pass, "f_createResource: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
						v_resourceIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, p_parentIndex);
						if(match(int2, p_resourceType) or match(-1, p_parentIndex)) {//If created resource is an AE or created under CSEBase, it needs to be added to the resourceToBeDeleted list
							vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_resourceIndex};
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, "f_createResource: Error while creating resource type " & int2str(enum2int(p_resourceType)));
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, "f_createResource: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, "f_createResource: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
					}
				}	
    			
				return v_resourceIndex;
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
			/**
			 * @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 
			 */
			function f_cse_createAccessControlPolicyAux(in template (value) XSD.String p_acpName := c_acpAuxName, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer{
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_acpAuxIndex := -1;
    			
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
    			
				v_request.to_ := f_getResourceAddress();
    			
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
						setverdict(pass, "f_createAccessControlPolicy: Resource type " & int2str(1) & " created successfuly");
						v_acpAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent);
						vc_acpAuxIndex := v_acpAuxIndex;
						vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_acpAuxIndex};
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, "f_createAccessControlPolicy: Error while creating resource type " & int2str(1));
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, "f_createAccessControlPolicy: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, "f_createAccessControlPolicy: No answer while creating resource type " & int2str(1));
					}
				}	
    		
				return v_acpAuxIndex;
424
    
425
			}
426 427
    			
    			
428 429 430 431 432 433 434
			/**
			 * @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 {
435
    		
436 437 438 439
				var MsgIn v_response;
				var RequestPrimitive v_request;
				var integer v_acpAuxIndex := -1;
				var integer v_containerResourceIndex := -1;
440
    			
441
				v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_acpName := c_acpAuxName);//"MyAcp_2"
442
    			
443 444 445
				v_request := valueof(m_createContainerBase);
				v_request.primitiveContent.any_1[0].Container_optional.accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)};
				v_request.primitiveContent.any_1[0].Container_optional.resourceName := "MyContainerAux";
446
    			
447
				v_containerResourceIndex := f_cse_createResource(int3, v_request, p_parentIndex);
448
    			
449
				return v_containerResourceIndex;		
450
    	
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
			}
    		
			/**
			 * @desc 
			 * @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;
						setverdict(pass, testcasename() & ": Attribute of resource updated successfuly");
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value v_response {
						tc_ac.stop;
						setverdict(fail, testcasename() & ": Error while updating resource");
					}
					[] mcaPort.receive{
						tc_ac.stop;
						setverdict(fail, testcasename() & ": Error, unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while updating resource");
					}
				}	
			}// end f_cse_updateResource
    		
			/**
			 * @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.primitiveContent.any_1[0].AccessControlPolicy_optional.privileges.accessControlRule_list := {
					{
						accessControlOriginators := PX_ACOR, //{"admin:admin"}
						accessControlOperations := valueof(p_allowedOperations),
						accessControlContexts_list := {}
					}
				};
500
    						
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 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
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK))  {
						tc_ac.stop;
						setverdict(pass, "f_updateAcpAuxResource: " & v_request.to_ & " resource updated successfuly");
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(fail, "f_updateAcpAuxResource: Error while updating " & v_request.to_ & " resource");
					}
					[] tc_ac.timeout {
						setverdict(inconc, "f_updateAcpAuxResource: No answer while updating " & v_request.to_ & " resource" );
					}
				}		
			}   
    		
		function f_subscriptionVerificationHandler(in XSD.ID p_creator, in ResponseStatusCode v_responseStatusCode := int2001) runs on CseTester {
			// Local variables
			var MsgIn v_response;
			var ResponsePrimitive v_responsePrimitive;
			var template Notification v_notificationRequest := mw_contentNotificationBase;
			var PrimitiveContent v_notificationResponse; // TODO Need to see if this parameter is required however there is a problem if it s omitted during the verification
			
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);

			v_notificationResponse.any_1 := {{Notification := valueof(mw_contentNotificationAllOmit)}};
	
			v_notificationRequest.verificationRequest := true;
			v_notificationRequest.creator := p_creator;
			//v_notificationRequest.subscriptionReference := "I Don't know which URI is expected"; // TODO mandatory parameter 
			v_responsePrimitive := valueof(m_responseNotification(v_responseStatusCode,v_notificationResponse));//TODO No PrimitiveContent is expected
	
			if(v_responseStatusCode != int2001){
				v_responsePrimitive.primitiveContent := omit;
			}
	
			tc_ac.start;
			alt {
				[] mcaPort.receive(mw_request(mw_notify(v_notificationRequest))) -> value v_response {
					tc_ac.stop;
					setverdict(pass, testcasename() & ": Notification received");
					//mcaPort.send(m_response(p_responsePrimitive)); 						
				}
				[] mcaPort.receive(mw_request(mw_notify(mw_contentNotification(?)))) -> value v_response {
					tc_ac.stop;
					setverdict(fail, testcasename() & ": Notification received but verificationRequest isn't set to TRUE");							
				}
				[] mcaPort.receive{
					tc_ac.stop;
					setverdict(fail, testcasename() & ": Error, unexpected message received");
				}
				[] tc_ac.timeout {
					setverdict(inconc, testcasename() & ":  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_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.any_1[0].AE_optional)){
				if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.resource)) {
					v_matchResult := match(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.resource.AE_optional, p_primitiveContent.any_1[0].AE_optional)
				}
				else if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.responsePrimitive)) {
					v_matchResult :=match(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.responsePrimitive.primitiveContent.any_1[0].AE_optional, p_primitiveContent.any_1[0].AE_optional)
				}
				else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification)) {
					v_matchResult := true;
					v_numberOfAggregatedNotification := lengthof(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification.notification_list);
					for(i := 0; i< v_numberOfAggregatedNotification; i := i + 1){
						if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification.notification_list[i].notificationEvent.representation.resource)) {
							if(not (match(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification.notification_list[i].notificationEvent.representation.resource.AE_optional, p_primitiveContent.any_1[0].AE_optional))){
								v_matchResult := false;
							}
						}
						else if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification.notification_list[i].notificationEvent.representation.responsePrimitive)) {
							if(not (match(p_requestPrimitive.primitiveContent.any_1[0].AggregatedNotification.notification_list[i].notificationEvent.representation.responsePrimitive.primitiveContent.any_1[0].AE_optional, p_primitiveContent.any_1[0].AE_optional))){
								v_matchResult := false;
							}
						}						
					}
					if (i == 0){
						v_matchResult := false;
					}
				}

			}
	
			if (ischosen(p_primitiveContent.any_1[0].Container_optional)){
				if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.resource)) {
					v_matchResult := match(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.resource.Container_optional, p_primitiveContent.any_1[0].Container_optional)
				}
				else if(ischosen(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.responsePrimitive)) {
					v_matchResult := match(p_requestPrimitive.primitiveContent.any_1[0].Notification.notificationEvent.representation.responsePrimitive.primitiveContent.any_1[0].Container_optional, p_primitiveContent.any_1[0].Container_optional)
				}
			}
	
			return v_matchResult;

		} //end f_check_notificationContent	
		
		function f_cse_notifyProcedure(template PrimitiveContent p_primitiveContent) 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_notify(mw_contentNotification(?)))) -> value v_response {
					tc_ac.stop;
					if(f_check_notificationContent(v_response.primitive.requestPrimitive, p_primitiveContent)){
						setverdict(pass, testcasename() & ": Notification received");
						mcaPort.send(m_response(valueof(m_responseNotification(int2001))));
					}
					else{
						setverdict(fail, testcasename() & ": Notification received but the content doesn't match");
					}
				}
				[] mcaPort.receive{
					tc_ac.stop;
					setverdict(fail, testcasename() & ": Error, unexpected message received");
				}
				[] tc_ac.timeout {
					setverdict(inconc, testcasename() & ": No notification received");
				}
			}
641
    
642 643 644 645 646 647 648 649
    	
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort); 
    
		} //end f_cse_notifyProcedure
    		
    
		}//end group helpingFunctions
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
    	
		group altstepFunctions {
    		 
			/**
			  * @desc	Cse altstep for config 01
			  */
			 altstep a_cse_cf01() runs on CseTester {
		
				[] mcaPort.receive {
					log("a_default: WARNING: Unexpected message received");
					repeat;
				}
			 }			
    		 
			/**
			  * @desc	Cse altstep for config 02
			  */
			 altstep a_cse_cf02() runs on CseTester {
    		
				[] mcaPort.receive {
					log("a_default: WARNING: Unexpected message received");
					repeat;
				}
				[] mccPort.receive {
					log("a_default: WARNING: Unexpected message received");
					repeat;
				}
			 }	

		}//end group altstepFunctions	
    	
	}//end cseFunctions
682
	
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	group aeFunctions {
		
		group altstepFunctions {
    
			/**
			  * @desc	Ae altstep
			  */
			 altstep a_ae_default() runs on AeTester {
    		
				[] mcaPort.receive {
					log("a_default: WARNING: Unexpected message received");
					repeat;
				}
			 }		
    		 
		}//end group altstepFunctions
		
	}//end of aeFunctions

702

703 704
	group getSetFunctions {
    
705 706 707 708 709 710 711
		/**
		 * @desc Creation of a CREATE request primitive from a template request primitive
		 * @param p_resourceType Type of resource to be created
		 * @param p_request Template request primitive 
		 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
		 * @return Created CREATE request primitive
		 * @verdict 
712
		 */
713 714
		function f_getCreateRequestPrimitive(in ResourceType p_resourceType, template RequestPrimitive p_request := m_create, integer p_parentIndex) runs on CseTester return RequestPrimitive {
			var integer p_locresourceIndex := p_parentIndex;
715
			var template ListOfURIs v_defaultListOfURIs := {"Not Initialized"};
716
            
717
			p_request.from_ := f_getOriginator(p_parentIndex);
718 719
			p_request.to_ := f_getResourceAddress(p_parentIndex);
    		
720 721
			if (p_resourceType == int1) {//AccessControlPolicy
			} 
722
			
723
			if (p_resourceType == int9) {//group
724 725 726
				if(match(valueof(p_request.primitiveContent.any_1[0].Group_optional.memberIDs), v_defaultListOfURIs )){
					p_request.primitiveContent.any_1[0].Group_optional.memberIDs := {f_getResourceAddress(p_parentIndex)};
				}
727
			}
728 729 730 731 732 733 734 735
			
			if(p_resourceType == int3){//container
				//when a container is created by hosting cse for storing location information, the container is seen as a location container
				if(PX_IS_LOC_CONTAINER){
					p_request.primitiveContent.any_1[0].Container_optional.locationID := f_getResourceId(vc_resourcesList[p_locresourceIndex].resource);//resourceID of the locationPolicy
				}		  
			}
			
736
			if (p_resourceType == int15) {//pollingChannel
737 738 739 740 741 742
				if(ischosen(vc_resourcesList[p_parentIndex].resource.any_1[0].AE_optional)) {	
					p_request.from_ := vc_resourcesList[p_parentIndex].resource.any_1[0].AE_optional.aE_ID;
				}
			} 
			
			if (p_resourceType == int18) {//schedule
743
			} 
744
    			
745
			if (p_resourceType == int23) {//subscription
746
				if(match(valueof(p_request.primitiveContent.any_1[0].Subscription_optional.notificationURI), v_defaultListOfURIs )){
747 748
					p_request.primitiveContent.any_1[0].Subscription_optional.notificationURI := {f_getResourceAddress(p_parentIndex)};
				}
749
				/*if(PX_FROM_IS_AE_ID) {
750 751 752 753 754 755
					if(PX_UNSTRUCTURED){
						p_request.primitiveContent.any_1[0].Subscription_optional.notificationURI := {vc_aeAux.aE_ID};
					} else {
						p_request.primitiveContent.any_1[0].Subscription_optional.notificationURI := {PX_CSE_ID & "/" & vc_aeAux.aE_ID};
					}
				} else {
oneM2MTester Develop Team's avatar
oneM2MTester Develop Team committed
756
					p_request.primitiveContent.any_1[0].Subscription_optional.notificationURI := {"/" & PX_CSE_NAME & "/" & PX_AEAUX_NAME};//c_aeAuxName
757
				}*/
758
			}
759
    		
760 761
			return valueof(p_request);
		}
762
    	
763 764 765 766 767 768 769
		/**
		 * @desc Creation of an UPDATE request primitive from a template request primitive
		 * @param p_resourceType Type of resource to be created
		 * @param p_resourceIndex Internal resource index which indicates the resource to be updated
		 * @param p_request Template request primitive
		 * @return Created UPDATE request primitive
		 * @verdict 
770
		 */
771 772
		function f_getUpdateRequestPrimitive(in ResourceType p_resourceType, integer p_resourceIndex, template RequestPrimitive p_request) runs on CseTester return RequestPrimitive {
    		
773
			p_request.from_ := f_getOriginator(p_resourceIndex);
774
                
775
			p_request.to_ := f_getResourceAddress(p_resourceIndex);
776
    			
777
			if (p_resourceType == int3) {//Container
778
    			
779 780
			//TODO
			} 
781
    		
782 783
			if (p_resourceType == int9) {//group
				//TODO	
784
    		
785
			}
786
    		
787 788
			if (p_resourceType == int18) {//schedule
				//TODO			
789
    	
790
			} 
791
    
792 793 794
			if (p_resourceType == int15) {//pollingChannel
				//TODO		
			}
795
    		
796 797 798
			if (p_resourceType == int23) {//subscription
				//TODO		
			} 
799
    		
800 801
			return 	valueof(p_request);
		}
802
    
803 804 805 806 807
		/**
		 * @desc Extraction from a primitiveContent field the resourceID attribute
		 * @param p_contentResource primitiveContent field
		 * @return resourceID attribute
		 * @verdict 
808
		 */
809
		function f_getResourceId(PrimitiveContent p_contentResource) return XSD.ID {
810
    				
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
			if(ischosen(p_contentResource.any_1[0].AccessControlPolicy_optional)) {
				return p_contentResource.any_1[0].AccessControlPolicy_optional.resourceID;
			}
			if(ischosen(p_contentResource.any_1[0].Container_optional)) {
				return p_contentResource.any_1[0].Container_optional.resourceID;
			}
			if(ischosen(p_contentResource.any_1[0].Schedule_optional)) {
				return p_contentResource.any_1[0].Schedule_optional.resourceID;
			}
			if(ischosen(p_contentResource.any_1[0].PollingChannel_optional)) {
				return p_contentResource.any_1[0].PollingChannel_optional.resourceID;
			}
			if(ischosen(p_contentResource.any_1[0].Subscription_optional)) {
				return p_contentResource.any_1[0].Subscription_optional.resourceID;
			}
			if(ischosen(p_contentResource.any_1[0].Group_optional)) {
				return p_contentResource.any_1[0].Group_optional.resourceID;
828
			}
829 830 831 832
			if(ischosen(p_contentResource.any_1[0].AE_optional)) {
				return p_contentResource.any_1[0].AE_optional.resourceID;
			}
			return "1";
833
      
834
		}
835
    		
836 837 838 839 840
		/**
		 * @desc Extraction from a primitiveContent field the resourceName attribute
		 * @param p_contentResource primitiveContent field
		 * @return resourceName attribute
		 * @verdict 
841
		 */
842
		function f_getResourceName(PrimitiveContent p_contentResource) return XSD.ID {
843
    				
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
			if(ischosen(p_contentResource.any_1[0].AccessControlPolicy_optional)) {
				return p_contentResource.any_1[0].AccessControlPolicy_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].Container_optional)) {
				return p_contentResource.any_1[0].Container_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].Schedule_optional)) {
				return p_contentResource.any_1[0].Schedule_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].PollingChannel_optional)) {
				return p_contentResource.any_1[0].PollingChannel_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].Subscription_optional)) {
				return p_contentResource.any_1[0].Subscription_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].Group_optional)) {
				return p_contentResource.any_1[0].Group_optional.resourceName;
			}
			if(ischosen(p_contentResource.any_1[0].AE_optional)) {
				return p_contentResource.any_1[0].AE_optional.resourceName;
			}
865
    			
866
			return "1";
867
      
868
		}
869
    		
870 871 872 873 874
		/**
		 * @desc Resolution of the originator field (from) for a given resource
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @return Originator for a given resource
		 * @verdict 
875
		 */
876 877
		function f_getOriginator(integer  p_targetResourceIndex := -1) runs on CseTester return XSD.AnyURI {
    			
878
			if(p_targetResourceIndex == -1) {
879
				return PX_SUPER_USER;
880
			}	
881
    			
882 883 884 885 886 887 888
			if(PX_FROM_IS_AE_ID) {
				if(ischosen(vc_resourcesList[p_targetResourceIndex].resource.any_1[0].AE_optional)) {
					return vc_resourcesList[p_targetResourceIndex].resource.any_1[0].AE_optional.aE_ID;
				} else {
					return f_getOriginator(vc_resourcesList[p_targetResourceIndex].parentIndex);
				}
			} else {
889
				return PX_SUPER_USER;
890 891
			}
		}
892
    		
893 894 895 896 897 898
		/**
		 * @desc Return of a index of a specific attribute from an attributeList by attributeName
		 * @param p_attributeList Target attributeList
		 * @param p_attributeName attributeName to be searched
		 * @return Index of the attribute in the attributeList
		 * @verdict 
899
		 */
900
		function f_getAttribute(in AttributeList p_attributeList, in XSD.NCName p_attributeName) return integer {
901 902
		var integer i;
		var Attribute v_attribute := {-, -};
903
    		
904
		for (i:=0; i < lengthof(p_attributeList); i := i + 1){
905 906
			if(p_attributeList[i] == p_attributeName){
				return i;
907 908
			}	
		}
909
    			
910
		return -1;
911
    		
912
		}
913
    		
914 915 916 917 918
		/**
		 * @desc Resolution of the resource address field (to) for a given resource depending on addressing and hierarchical format 
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @return Resource address for the given resource
		 * @verdict 
919
		 */
920
		function f_getResourceAddress(integer  p_targetResourceIndex := -1) runs on CseTester return XSD.ID {
921
			var XSD.ID v_resourceAddress;
922
    		
923
			if(PX_ADDRESSING_FORMAT == e_cseRelative) {
924
    				
925 926 927 928 929 930 931 932 933 934 935 936 937 938
				if(PX_UNSTRUCTURED) {
					if(p_targetResourceIndex == -1) {
						return "";
					} else {
						return f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
					}
				} else {
					if(p_targetResourceIndex == -1) {
						return PX_CSE_NAME;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}
939
    				
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
			} else if (PX_ADDRESSING_FORMAT == e_spRelative) {
				if(PX_UNSTRUCTURED) {
					if(p_targetResourceIndex == -1) {
						return "/" & PX_CSE_ID;
					} else {
						v_resourceAddress := f_getResourceAddress() & "/" & f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else {
					if(p_targetResourceIndex == -1) {
						return "/" & PX_CSE_ID & "/" & PX_CSE_NAME;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				}
			} else if (PX_ADDRESSING_FORMAT ==  e_absolute) {
				if(PX_UNSTRUCTURED) {
					if(p_targetResourceIndex == -1) {
959
						return "//" &"SpId" & "/" & PX_CSE_ID;
960
					} else {
961 962
						v_resourceAddress := f_getResourceAddress() & "/" & f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
963 964 965
					}
				} else {
					if(p_targetResourceIndex == -1) {
966
						return "//" &"SpId" & "/" & PX_CSE_ID & "/" & PX_CSE_NAME;
967
					} else {
968 969
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
970 971 972 973 974
					}	
				}				
			} else {
				return "";
			}
975
    			
976
		}
977 978 979 980 981 982
		/**
		 * @desc Saving of a resource and its parent index in the internal resource list
		 * @param p_resource Resource to be saved
		 * @param p_parentIndex Parent index of resource to be saved
		 * @return Internal resource index of the saved resource
		 * @verdict 
983
		 */
984
		function f_setResource(PrimitiveContent p_resource, integer  p_parentIndex := -1) runs on Tester return integer {
985
    			
986 987 988 989 990 991
			if(isbound(vc_resourcesList)) {
				vc_resourcesList[lengthof(vc_resourcesList)] := {p_parentIndex, p_resource};
			} else {
				vc_resourcesList[0] := {p_parentIndex, p_resource};
			}
			return lengthof(vc_resourcesList)-1;
992
    					
993
		}
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
		
    				
		/**
		 * @desc Set Acpid into the requestPrimitive
		 * @param p_requestPrimitive RequestPrimitive to be modified
		 * @param p_accessControlPolicyIDs AcpId to be set
		 * @return 
		 * @verdict 
		 */
		function f_setAcpId(template RequestPrimitive p_requestPrimitive, template AcpType p_accessControlPolicyIDs) runs on CseTester return RequestPrimitive{
	
			if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].AE_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].AE_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].Container_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].Container_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].Group_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].Group_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].ServiceSubscribedAppRule_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].ServiceSubscribedAppRule_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].Subscription_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].Subscription_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.any_1[0].LocationPolicy_optional)){
				p_requestPrimitive.primitiveContent.any_1[0].LocationPolicy_optional.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			return valueof(p_requestPrimitive);					
		}
1025
    				
1026 1027
	}//end group getSetFunctions
	
1028
	group commonFunctions {
1029
		
1030 1031 1032 1033 1034 1035
		/**
		 * @desc Sending of an Adapter Control primitive
		 * @param event Action to be performed by TA
		 * @param data Corresponding information for the correct execution of the given action
		 * @verdict 
		 */
1036
		function f_sendAcPrimitive(in charstring event, in charstring data) runs on Tester {
1037 1038 1039 1040 1041

			var charstring v_data := "" & data; // clear encoding rules (ttwb issue ?)
			acPort.send(AcRequestPrimitive:{event, {charstring := v_data}});
			
		}
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
		
		group altstepFunctions {
    
			/**
			  * @desc	Default altstep
			  */
			 altstep a_default() runs on Tester {
    		
				[] tc_wait.timeout {
					 setverdict(inconc,"a_default: ERROR: Timeout while awaiting reaction of the IUT prior to Upper Tester action");
				}
				[] tc_ac.timeout {
					setverdict(inconc,"a_default: ERROR: Timeout while awaiting the reception of a message");
				}
			 }	    		 
1057

1058 1059 1060
		}//end group altstepFunctions
		
	}//end of commonFunctions
1061 1062
	
}  // end of module