LibItsDenm_Functions.ttcn 9.7 KB
Newer Older
/**
 *	@author 	ETSI / STF405
berge's avatar
berge committed
 *  @version 	$URL$
 *				$Id$
 *	@desc		Module containing functions for DENM
 *
 */
module LibItsDenm_Functions {
berge's avatar
berge committed
    // LibIts
    import from LibIts_TestSystem all;
    import from LibIts_Interface all; 
    import from LibItsCommon_Functions all;
tepelmann's avatar
tepelmann committed
    import from LibItsDenm_TypesAndValues all; 
    import from LibItsDenm_Templates all; 
    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;

berge's avatar
berge committed
    /**
     * @desc 	Create Facility component and connects DENM port
berge's avatar
berge committed
     * @remark	Only used when ItsFa is a PTC
berge's avatar
berge committed
     * @param	p_ptcDenm returned Facility component variable
     */    
berge's avatar
berge committed
    function f_ptcDenmUp(out ItsFa p_ptcDenm) {
berge's avatar
berge committed
        
        // Create Facility component
        p_ptcDenm := ItsFa.create("DENM Tester");
berge's avatar
berge committed
        
        // map ports
        map(p_ptcDenm:denmPort, system:denmPort);
        map(p_ptcDenm:utPort, system:utPort);
berge's avatar
berge committed
        
berge's avatar
berge committed
    } // end f_ptcDenmUp       
berge's avatar
berge committed
    
    /**
     * @desc 	Wait for component to finish and unmap DENM ports
berge's avatar
berge committed
     * @remark	Only used when ItsFa is a PTC
berge's avatar
berge committed
     * @param	p_camPtc Facility component variable
     */    
berge's avatar
berge committed
    function f_ptcDenmDown(in ItsFa p_ptcDenm) runs on ItsMtc {    
berge's avatar
berge committed
    	tc_guard.start;
        alt {
        	[] p_ptcDenm.done {
            	tc_guard.stop;
            }
            
            [] tc_guard.timeout {
berge's avatar
berge committed
             	log("*** f_ptcDenmDown: ERROR: Timeout while waiting for component ***");
berge's avatar
berge committed
             	setverdict(inconc);   
            }
        }
berge's avatar
berge committed
        unmap(p_ptcDenm:denmPort);
        unmap(p_ptcDenm:utPort);
berge's avatar
berge committed
    } // end f_ptcDenmDown
tepelmann's avatar
tepelmann committed
    group altsteps {
        
        /**
         * @desc The base default.
         */
        altstep a_default() runs on ItsFa {
            [] denmPort.receive {
berge's avatar
berge committed
                setverdict (inconc, "*** a_default: INCONC: Received an unexpected message ***");
tepelmann's avatar
tepelmann committed
                //TODO shall stop be called here?
                stop;
            }
            [] tc_wait.timeout {
berge's avatar
berge committed
                setverdict (inconc, "*** a_default: INCONC: Timeout while awaiting reaction of the IUT prior to Upper Tester action ***");
tepelmann's avatar
tepelmann committed
                //TODO shall stop be called here?
                stop;
            }
            [] tc_ac.timeout {
berge's avatar
berge committed
                setverdict (inconc, "*** a_default: INCONC: Timeout while awaiting the reception of a message ***");
tepelmann's avatar
tepelmann committed
                //TODO shall stop be called here?
                stop;
            }
        }
        
    } // 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 
         */
        function f_prInitialState() runs on ItsFa return FncRetCode {
            var FncRetCode v_ret := e_success;
            
            f_prDefault();
            
berge's avatar
berge committed
            f_utInitializeIut();
tepelmann's avatar
tepelmann committed
            
            f_setVerdictPreOrPostamble(v_ret);
            
            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
            f_setVerdictPreOrPostamble(v_ret);
            
        }
        
        /**
         * @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.
tepelmann's avatar
tepelmann committed
         */
        function f_poCancelEvent(template (value) Trigger p_trigger, template (value) Situation p_event) runs on ItsFa {
            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
                    )
                );
            }
            else {
                v_ret := f_utTriggerEvent(m_utEventCancellation(p_event, c_dataVersionCancellation));
tepelmann's avatar
tepelmann committed
            }
            f_setVerdictPreOrPostamble(v_ret);
            
            f_poDefault();
        }
        
    } // end group postambles
    
    group upperTester {
        
        /**
         * @desc    Requests to bring the IUT in an initial state
         */
berge's avatar
berge committed
        function f_utInitializeIut() runs on ItsFa {
            
            utPort.send(UtDenmInitialize:{});
            tc_ac.start;
            alt {
                [] utPort.receive(UtDenmResult:true) {
berge's avatar
berge committed
                    setverdict (pass, "*** f_utInitializeIut: PASS: IUT initialized ***");
                }
                [] utPort.receive {
berge's avatar
berge committed
                    setverdict (inconc, "*** f_utInitializeIut: INCONC: IUT could not be initialized ***");
                    stop;
                }
                [] tc_ac.timeout {
berge's avatar
berge committed
                    setverdict (inconc, "*** f_utInitializeIut: INCONC: IUT could not be initialized in time ***");
tepelmann's avatar
tepelmann committed
        
berge's avatar
berge committed
        /**
berge's avatar
berge committed
         * @desc    Triggers event from the application layer
         * @param   p_event The event to trigger.
berge's avatar
berge committed
         * @return 
tepelmann's avatar
tepelmann committed
         */
        function f_utTriggerEvent(template (value) UtDenmEvent p_event) runs on ItsFa return FncRetCode {
tepelmann's avatar
tepelmann committed
            var FncRetCode v_ret := e_success;
            var template (value) UtDenmTrigger v_utMsg := { p_event };
tepelmann's avatar
tepelmann committed
            
            utPort.send(v_utMsg);
tepelmann's avatar
tepelmann committed
            
            return v_ret;
        }
        
        /**
berge's avatar
berge committed
         * @desc    Checks that the event was indicated at the application layer
         * @param   p_event The event to check.
tepelmann's avatar
tepelmann committed
         * @return 
         */
        function f_utCheckEvent(template (value) UtDenmEvent p_event) runs on ItsFa return FncRetCode {
tepelmann's avatar
tepelmann committed
            var FncRetCode v_ret := e_success;
            var template (value) UtDenmCheck v_utMsg := { p_event };
            
            utPort.send(v_utMsg);
            tc_ac.start;
            alt {
                [] utPort.receive(UtDenmResult:true) {
berge's avatar
berge committed
                    setverdict (pass, "*** f_utCheckEvent: PASS: Event correctly indicated at application layer ***");
                    v_ret := e_success;
                }
                [] utPort.receive {
berge's avatar
berge committed
                    setverdict (fail, "*** f_utCheckEvent: FAIL: Event not correctly indicated at application layer ***");
                    v_ret := e_error;
                }
                [] tc_ac.timeout {
berge's avatar
berge committed
                    setverdict (inconc, "*** f_utCheckEvent: INCONC: Timeout while waiting for event check result ***");
                    v_ret := e_timeout;
                }
            }
tepelmann's avatar
tepelmann committed
            
            return v_ret;
        }
        
    } // end group upperTester
tepelmann's avatar
tepelmann committed
    
    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
         * @param p_rcvMsg The expected message to be received.
berge's avatar
berge committed

tepelmann's avatar
tepelmann committed
         */
        function f_awaitDenMessage(template (present) DenmInd p_rcvMsg) runs on ItsFa return FncRetCode {
tepelmann's avatar
tepelmann committed
            var DenmInd v_denmInd;
            return f_awaitDenMessageOut(p_rcvMsg, v_denmInd);
tepelmann's avatar
tepelmann committed
        }
        
        /**
         * @desc Awaits a DEN message
         * @param p_rcvMsg The expected message to be received.
         * @param p_rcvdMsg The received message - OUT.
         * @return 
         */
berge's avatar
berge committed
        function f_awaitDenMessageOut(in template (present) DenmInd p_rcvMsg, out DenmInd p_rcvdMsg) runs on ItsFa return FncRetCode {
berge's avatar
berge committed
            var FncRetCode v_ret := e_timeout;
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
                    v_ret := e_success;
                }
berge's avatar
berge committed
                [] tc_ac.timeout {
berge's avatar
berge committed
                	log("*** f_awaitDenMessageOut: INFO: Timeout while awaiting the reception of a message ***");
berge's avatar
berge committed
                	v_ret := e_timeout;
           		}
tepelmann's avatar
tepelmann committed
            }
            
            return v_ret;
        }
        
    } // end receiveFunctions
    
    group getFunctions {
        
        group iutGetFunctions {
            
            /**
berge's avatar
berge committed
             * @desc Gets IUT's default event duration
             * @return 
             */
            function f_getIutDefaultEventDuration() return TimeStamp {
berge's avatar
berge committed
                var TimeStamp v_iutDefaultEventDuration := 0;
                
                //TODO get the value from PIXIT or MIB
                
                return v_iutDefaultEventDuration;
            }            
            
berge's avatar
berge committed
        } // end iutGetFunctions
tepelmann's avatar
tepelmann committed
    } // end group getFunctions
    
} // end LibItsDenm_Functions