LibItsDenm_Functions.ttcn 8.27 KB
Newer Older
/**
 *	@author 	ETSI / STF405
berge's avatar
berge committed
 *  @version 	$URL$
 *				$Id$
 *	@desc		Module containing functions for DENM
 *
 */
module LibItsDenm_Functions {
    // LibCommon
    import from LibCommon_Sync all;
    import from LibCommon_VerdictControl all;
    
berge's avatar
berge committed
    // LibIts
    import from LibIts_TestSystem all;
    import from LibIts_Interface all; 
    import from LibItsCommon_Functions all;
garciay's avatar
garciay committed
    import from LibCommon_Time {
        modulepar PX_TNOAC;
        function f_sleep
    };
tepelmann's avatar
tepelmann committed
    import from LibItsDenm_TypesAndValues all; 
    import from LibItsDenm_Templates all; 
tepelmann's avatar
tepelmann committed
    import from LibItsDenm_Pics all; 
tepelmann's avatar
tepelmann committed
    import from CAM_PDU_Descriptions language "ASN.1:1997" all;
    import from DENM_PDU_Descriptions language "ASN.1:1997" all;
berge's avatar
berge committed
    
tepelmann's avatar
tepelmann committed
    // LibCommon
    import from LibCommon_VerdictControl all;

tepelmann's avatar
tepelmann committed
    group denmConfigurationFunctions {
berge's avatar
berge committed
        
        /**
         * @desc    Setups default configuration   
         */
        function f_cfUp() runs on ItsFa {
            
            map(self:utPort, system:utPort);
            map(self:denmPort, system:denmPort);
            f_connect4SelfOrClientSync();
            
        } // end f_cfUp
berge's avatar
berge committed
        
        /**
         * @desc    Deletes default configuration 
         */
        function f_cfDown() runs on ItsFa {
            
            unmap(self:utPort, system:utPort);
garciay's avatar
garciay committed
            unmap(self:denmPort, system:denmPort);
            f_disconnect4SelfOrClientSync();
            
        } // end f_cfDown
berge's avatar
berge committed
        
tepelmann's avatar
tepelmann committed
    } //end denmConfigurationFunctions
tepelmann's avatar
tepelmann committed
    group altsteps {
        
        /**
         * @desc The base default.
         */
        altstep a_default() runs on ItsFa {
berge's avatar
berge committed
        	[] denmPort.receive(mw_denmInd(mw_denmPdu(mw_anyDenm))) { 
berge's avatar
berge committed
                log("*** a_default: INFO: DENM message received in default ***");
                vc_denmReceived := true;
                repeat;
            }
tepelmann's avatar
tepelmann committed
            [] denmPort.receive {
                log("*** a_default: ERROR: Received an unexpected message ***");
berge's avatar
berge committed
                f_selfOrClientSyncAndVerdict("error", e_error);
tepelmann's avatar
tepelmann committed
            }
            [] tc_wait.timeout {
                log("*** a_default: INCONC: Timeout while awaiting reaction of the IUT prior to Upper Tester action ***");
berge's avatar
berge committed
                f_selfOrClientSyncAndVerdict("error", e_timeout);
tepelmann's avatar
tepelmann committed
            }
            [] tc_ac.timeout {
                log("*** a_default: INCONC: Timeout while awaiting the reception of a message ***");
berge's avatar
berge committed
                f_selfOrClientSyncAndVerdict("error", e_timeout);
tepelmann's avatar
tepelmann committed
            }
tepelmann's avatar
tepelmann committed
            [] a_shutdown() {
                f_poDefault();
                f_cfDown();
                log("*** a_default: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
                stop;   
            }
        }
        
        /**
         * @desc Default handling the cancellation of an event.
         * @param p_trigger Indicates if the cancellation have to be raised by the test system(e_ets) 
         *                  or at the application layer of the IUT(e_iut).
         * @param p_event The event to cancel.
         * @param p_actionId The action ID of the event to be cancelled
tepelmann's avatar
tepelmann committed
         */
        altstep a_cancelEvent(in template (value) Trigger p_trigger, in template (value) Situation p_event, in template (omit) ActionID p_actionId) 
        runs on ItsFa {
tepelmann's avatar
tepelmann committed
            [] a_shutdown() {
                f_poCancelEvent(p_trigger, p_event, p_actionId);
tepelmann's avatar
tepelmann committed
                f_cfDown();
                log("*** a_cancelEvent: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
tepelmann's avatar
tepelmann committed
                stop;   
            }
tepelmann's avatar
tepelmann committed
        }
        
    } // end group altsteps
    
    group preambles {
        
        /**
         * @desc The default preamble.
         */
        function f_prDefault() runs on ItsFa {
            vc_default := activate(a_default());
        }
        
        /**
         * @desc Brings the IUT into an initial state.
         * @return FncRetCode 
tepelmann's avatar
tepelmann committed
         */
        function f_prInitialState() runs on ItsFa return FncRetCode {
            var FncRetCode v_ret := e_success;
            
            f_utInitializeIut(m_denmInitialize);

			f_prDefault();
tepelmann's avatar
tepelmann committed
            
            return v_ret;
        }
        
    } // end group preambles
    
    group postambles {
        
        /**
         * @desc The default postamble.
         */
        function f_poDefault() runs on ItsFa {
            var FncRetCode v_ret := e_success;
            //empty
        }
        
        /**
         * @desc Postamble including cancellation of an event.
         * @param p_trigger Indicates if the cancellation have to be raised by the test system(e_ets) 
         *                  or at the application layer of the IUT(e_iut).
berge's avatar
berge committed
         * @param p_event The event to cancel.
         * @param p_actionId The action ID of the event to be cancelled
tepelmann's avatar
tepelmann committed
         */
        function f_poCancelEvent(template (value) Trigger p_trigger, template (value) Situation p_event, template (omit) ActionID p_actionId) 
        runs on ItsFa {
tepelmann's avatar
tepelmann committed
            var FncRetCode v_ret := e_success;
            
berge's avatar
berge committed
            if (valueof(p_trigger) == e_ets) {
                f_sendDenMessage(
tepelmann's avatar
tepelmann committed
                    m_denmReq(
                    	m_denmPdu(
                        	m_denmWithCause(c_dataVersionCancellation, p_event, m_eventPosition(f_getTsCurrentPosition()), f_getTsStationId())
tepelmann's avatar
tepelmann committed
                    )
                );
garciay's avatar
garciay committed
                f_sleep(PX_TNOAC);
tepelmann's avatar
tepelmann committed
            }
            else {
berge's avatar
berge committed
            	f_utTriggerEvent(m_utUpdateEventExpirationTime(p_event, p_actionId, 1));
                f_utTriggerEvent(m_utEventCancellation(p_event, p_actionId));
tepelmann's avatar
tepelmann committed
            }
            
            f_poDefault();
        }
        
    } // end group postambles
    
    group sendFunctions {
        
        /**
         * @desc Sends a DEN message
         * @param p_sendMsg The DEN message to send.
         */
        function f_sendDenMessage(template (value) DenmReq p_sendMsg) runs on ItsFa {
            p_sendMsg.msgOut.denm.management.actionID.sequenceNo := vc_sequenceNo;
tepelmann's avatar
tepelmann committed
            
            denmPort.send(p_sendMsg);
        }
        
    } // end sendFunctions
    
    group receiveFunctions {
        
        /**
         * @desc Awaits a DEN message and returns it
tepelmann's avatar
tepelmann committed
         * @param p_rcvMsg The expected message to be received.
         * @param p_rcvdMsg The received message - OUT.
         */
        function f_awaitDenMessage(in template (present) DenmInd p_rcvMsg, out DenmInd p_rcvdMsg) runs on ItsFa {
tepelmann's avatar
tepelmann committed
            
berge's avatar
berge committed
            tc_ac.start;
tepelmann's avatar
tepelmann committed
            alt {
                [] denmPort.receive(p_rcvMsg) -> value p_rcvdMsg {
berge's avatar
berge committed
                    tc_ac.stop;
tepelmann's avatar
tepelmann committed
                }
berge's avatar
berge committed
                [] tc_ac.timeout {
                    log("*** f_awaitDenMessage: INFO: Timeout while awaiting the reception of a message ***");
berge's avatar
berge committed
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
tepelmann's avatar
tepelmann committed
            }
            
        }
        
    } // end receiveFunctions
    
    group getFunctions {
        
        group iutGetFunctions {
            
            /**
berge's avatar
berge committed
             * @desc Gets IUT's default event duration
             * @return Default expiry time of DENM events
             */
            function f_getIutDefaultEventDuration() return TimeStamp {
tepelmann's avatar
tepelmann committed
                return PICS_DEFAULT_EXPIRY_TIME;
berge's avatar
berge committed
        } // end iutGetFunctions
tepelmann's avatar
tepelmann committed
    } // end group getFunctions
    
    group miscFunctions {
    	
    	/**
    	 * @desc       Gets a random severity
    	 * @return     Random Severity 
    	 */
    	function f_randomSeverity() return Severity {
    	   	var integer v_rnd := f_random(1, 4);
    	   	select(v_rnd) {
    	   	   case(1) {
    	   	       return informative;
    	   	   } 
               case(2) {
                   return obstacles;
               }
               case(3) {
                   return danger;
               } 
               case(4) {
                   return highestDanger;
               }
    	   	   case else {
    	   	   	   return highestDanger;
    	   	   }    	
    	   	}    	   	
    	}
    } // end miscFunctions
    
} // end LibItsDenm_Functions